package com.jmpt.fangbohui.ui;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.ViewTreeObserver;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AnimationSet;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.jmpt.fangbohui.Constants;
import com.jmpt.fangbohui.R;
import com.jmpt.fangbohui.adapter.HouseSelectProportionAdapter;
import com.jmpt.fangbohui.adapter.HouseSeleteMoreAdapter;
import com.jmpt.fangbohui.adapter.HouseSeleteMoreRightAdapter;
import com.jmpt.fangbohui.adapter.NewHouseListAdapter;
import com.jmpt.fangbohui.adapter.NewHouseSelectOrderAdapter;
import com.jmpt.fangbohui.adapter.NewHouseSelectPriceAdapter;
import com.jmpt.fangbohui.adapter.NewHouseSelectRegionAdapter;
import com.jmpt.fangbohui.adapter.OldHouseListAdapter;
import com.jmpt.fangbohui.bean.HouseMoreCategoryItemValuesBean;
import com.jmpt.fangbohui.bean.HouseMoreSeleteCategoryBean;
import com.jmpt.fangbohui.bean.HouseProportionBean;
import com.jmpt.fangbohui.bean.NewHouseBean;
import com.jmpt.fangbohui.bean.OldHouseBean;
import com.jmpt.fangbohui.helper.CommonHelper;
import com.jmpt.fangbohui.http.ApiRequest;
import com.jmpt.fangbohui.http.JsonHttpHandler;
import com.jmpt.fangbohui.ui.BuyNewHouseListActivity.HttpNewHouseListHandler;
import com.jmpt.fangbohui.ui.base.BaseHeadActivity;
import com.jmpt.fangbohui.utils.DebugLog;
import com.jmpt.fangbohui.utils.ImageLoaderHelper;
import com.jmpt.fangbohui.utils.ToastHelper;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.PauseOnScrollListener;

public class BuyOldHouseListActivity extends BaseHeadActivity implements OnClickListener {
	
	private static final String TAG = "BuyOldHouseListActivity.java";
	protected static final int SEARCH_REQUEST_CODE = 1212;
	private Button btn_locationSelete;
	private Button btn_priceSelete;
	//面积选择按钮
	private Button btn_proportionSelete;
	private Button btn_moreSelete;
	private PullToRefreshListView plv_houseList;
	private RelativeLayout mLoading;
	private ViewStub vs_seleteArea;
	private OldHouseListAdapter mHouseListAdapter;
	private boolean isFirstLoad;
	private boolean isNoMore;
	private NewHouseSelectRegionAdapter mSeleteRegionAdapter;
	private NewHouseSelectPriceAdapter mSeletePriceAdapter;
	private HouseSelectProportionAdapter mSelectProportionAdapter;
	private HouseSeleteMoreAdapter mSelectMoreLeftAdapter;
	private HouseSeleteMoreRightAdapter mSeleteMoreRightAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_oldhouse_list);
		// 设置标题
		showTitle("买二手房");
		// 设置返回键
		showBackButton(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		showRightImageButton(R.drawable.ic_home_search,
				new View.OnClickListener() {
					@Override
					public void onClick(View view) {
						Intent intent = new Intent(getApplicationContext(),
								SearchActivity.class);
						intent.putExtra(SearchActivity.CURR_KEY, searchKey);
						startActivityForResult(intent, SEARCH_REQUEST_CODE);
					}
				});

		assignViews();

		initView();
	}

	private void initView() {
//		addMenuItem(R.drawable.btn_main_home,"主页");
//		addMenuItem(R.drawable.btn_main_home,"搜索1");
//		addMenuItem(R.drawable.btn_main_home,"搜索2");
		mHouseListAdapter = new OldHouseListAdapter(this);
		plv_houseList.setAdapter(mHouseListAdapter);
		plv_houseList.setMode(PullToRefreshBase.Mode.BOTH);
		plv_houseList
				.setOnItemClickListener(new AdapterView.OnItemClickListener() {
					@Override
					public void onItemClick(AdapterView<?> adapterView,
							View view, int i, long l) {
						 //显示房屋详情
						 Intent intent = new Intent(BuyOldHouseListActivity.this, OldHouseDetailActivity.class);
						 intent.putExtra(OldHouseDetailActivity.HOUSE_ID, mHouseListAdapter.houseList.get(i - 1).HouseID);
						 intent.putExtra(OldHouseDetailActivity.HOUSE_TITLE, mHouseListAdapter.houseList.get(i - 1).H_Title);
						 startActivity(intent);
					}
				});
		
		plv_houseList
				.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
					@Override
					public void onPullDownToRefresh(
							PullToRefreshBase<ListView> refreshView) {
						fistLoad();
					}
					@Override
					public void onPullUpToRefresh(
							PullToRefreshBase<ListView> refreshView) {
						if(isNoMore){
							ToastHelper.ShowToast("没有更多数据了", getApplicationContext());
							plv_houseList.onRefreshComplete();
							return;
						}
						// 加载更多
						loadMore();
					}
				});
		
		plv_houseList.setOnScrollListener(new PauseOnScrollListener(ImageLoaderHelper.getImageLoader(), true, true));  

		//初次化区域数据 适配器
		mSeleteRegionAdapter = new NewHouseSelectRegionAdapter(this);
		mSeleteRegionAdapter.data = CommonHelper.getOldHouseRegionBeans();
		
		//初始化总价范围数据 适配器
		mSeletePriceAdapter = new NewHouseSelectPriceAdapter(this);
		mSeletePriceAdapter.data = CommonHelper.getOldHousePriceBeans();
		
		//初次化面积数据 适配器
		mSelectProportionAdapter = new HouseSelectProportionAdapter(this);
		mSelectProportionAdapter.data = CommonHelper.getOldHouseProportionBeans();
		
		//初次化更多筛选分类列表数据 适配器
		mSelectMoreLeftAdapter = new HouseSeleteMoreAdapter(this);
		mSelectMoreLeftAdapter.data = CommonHelper.getOldHouseMoreCategoryBeans();
		
		//初次化更多筛选分类列表数据 适配器
		mSeleteMoreRightAdapter = new HouseSeleteMoreRightAdapter(this, null);
		
		initSeleteView();

		btn_locationSelete.setOnClickListener(this);
		btn_priceSelete.setOnClickListener(this);
		btn_proportionSelete.setOnClickListener(this);
		btn_moreSelete.setOnClickListener(this);
		
		fistLoad();

	}
	
	private void fistLoad() {
		isNoMore = false;
		load(true);
	}

	private void assignViews() {

		btn_locationSelete = (Button) findViewById(R.id.btn_oldhouse_list_locationSelete);
		btn_priceSelete = (Button) findViewById(R.id.btn_oldhouse_list_priceSelete);
		btn_proportionSelete = (Button) findViewById(R.id.btn_oldhouse_list_proportionSelete);
		btn_moreSelete = (Button) findViewById(R.id.btn_oldhouse_list_moreSelete);

		plv_houseList = (PullToRefreshListView) findViewById(R.id.plv_oldhouse_list_content);
		mLoading = (RelativeLayout) findViewById(R.id.rel_oldhouse_list_loading);
		vs_seleteArea = (ViewStub) findViewById(R.id.vs_oldhouse_list_seleteArea);
		// 查找筛选区域视图
		v_seleteArea = vs_seleteArea.inflate();
		v_seleteArea.setVisibility(View.INVISIBLE);
		assignSeleteViews(v_seleteArea);
	}

	private ImageView iv_seleteArea;
	private ListView lv_seleteArea_left;
	private ListView lv_seleteArea_right;
	private View v_seleteArea;
	protected int mCurrenLocationIndex;
	protected int mCurrenHouseTotalPriceIndex;
	protected int mCurrenProportionIndex;
	private int mCurrenMoreLeftIndex;
	private int mCurrenMoreRightIndex;
	//一页显示10条数据
	private int limit = Constants.limit.NEW_HOUSE_PAGE_LIMIT;

	private void assignSeleteViews(View view) {
		iv_seleteArea = (ImageView) view
				.findViewById(R.id.iv_house_group_select_background);
		lv_seleteArea_left = (ListView) view
				.findViewById(R.id.lv_house_group_select_left);
		lv_seleteArea_right = (ListView) view
				.findViewById(R.id.lv_house_group_select_right);

	}

	public void initSeleteView() {
		lv_seleteArea_left
				.setOnItemClickListener(new AdapterView.OnItemClickListener() {
					@Override
					public void onItemClick(AdapterView<?> parent, View view,
							int position, long id) {
						if (lv_seleteArea_left.getAdapter() instanceof NewHouseSelectRegionAdapter) {

							mCurrenLocationIndex = position;
							for (int i = 0; i < mSeleteRegionAdapter.data
									.size(); i++) {
								mSeleteRegionAdapter.data.get(i).isSelete = false;
							}
							mSeleteRegionAdapter.data.get(position).isSelete = true;
							mSeleteRegionAdapter.notifyDataSetChanged();
							hideSeleteArea();
							fistLoad();
							refreshLocationButtonName();
						}
						if (lv_seleteArea_left.getAdapter() instanceof NewHouseSelectPriceAdapter) {
							mCurrenHouseTotalPriceIndex = position;
							for (int i = 0; i < mSeletePriceAdapter.data.size(); i++) {
								mSeletePriceAdapter.data.get(i).isSelete = false;
							}
							mSeletePriceAdapter.data.get(position).isSelete = true;
							mSeletePriceAdapter.notifyDataSetChanged();
							hideSeleteArea();
							fistLoad();
							refreshPriceButtonName();
						}
						if (lv_seleteArea_left.getAdapter() instanceof HouseSelectProportionAdapter) {
							mCurrenProportionIndex = position;
							for (int i = 0; i < mSelectProportionAdapter.data.size(); i++) {
								mSelectProportionAdapter.data.get(i).isSelete = false;
							}
							mSelectProportionAdapter.data.get(position).isSelete = true;
							mSelectProportionAdapter.notifyDataSetChanged();
							hideSeleteArea();
							fistLoad();
							refreshProportionButtonName();
						}
						//TODO more selete
						if (lv_seleteArea_left.getAdapter() instanceof HouseSeleteMoreAdapter) {
							mCurrenMoreLeftIndex= position; 
							if (mSelectMoreLeftAdapter.data.get(position).values == null 
									|| mSelectMoreLeftAdapter.data.get(position).values.size() == 0) {
		                        for (int i = 0; i < mSelectMoreLeftAdapter.data.size(); i++) {
		                        	mSelectMoreLeftAdapter.data.get(i).isSelete = false;
		                        	mSelectMoreLeftAdapter.data.get(i).childSelete = -1;
		                        }
		                        mSelectMoreLeftAdapter.data.get(position).isSelete = true;
		                        mSelectMoreLeftAdapter.notifyDataSetChanged();
		                        hideSeleteArea();
		                        fistLoad();
		                    } else {
		                    	for (int i = 0; i < mSelectMoreLeftAdapter.data.size(); i++) {
		                    		mSelectMoreLeftAdapter.data.get(i).isSelete = false;
								}
		                    	mSelectMoreLeftAdapter.data.get(position).isSelete = true;
		                    	mSeleteMoreRightAdapter.data = mSelectMoreLeftAdapter.data.get(position);
		                    	mSelectMoreLeftAdapter.notifyDataSetChanged();
		                    	mSeleteMoreRightAdapter.notifyDataSetChanged();
		                    }
						}
					}
				});

		lv_seleteArea_right
				.setOnItemClickListener(new AdapterView.OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> parent, View view,
							int position, long id) {
						for (int i = 0; i < mSelectMoreLeftAdapter.data.size(); i++) {
							if (mSelectMoreLeftAdapter.data.get(i) == mSeleteMoreRightAdapter.data) {
								mCurrenMoreLeftIndex = i;
								mSelectMoreLeftAdapter.data.get(i).isSelete = true;
							} else {
								mSelectMoreLeftAdapter.data.get(i).isSelete = false;
							}
						}
						
						mSeleteMoreRightAdapter.data.childSelete = position;
						
						mSelectMoreLeftAdapter.notifyDataSetChanged();
						hideSeleteArea();
						fistLoad();
					}
				});
		iv_seleteArea.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				hideSeleteArea();
			}
		});
	}

	private void refreshProportionButtonName() {
		if(mCurrenProportionIndex == 0){
			btn_proportionSelete
			.setText("面积");
		}else{
			btn_proportionSelete
			.setText(mSelectProportionAdapter.data.get(mCurrenProportionIndex).h_mjName);
		}
	}

	protected void refreshPriceButtonName() {
		if(mCurrenHouseTotalPriceIndex == 0){
			btn_priceSelete.setText("总价");
		}else{
			btn_priceSelete
			.setText(mSeletePriceAdapter.data.get(mCurrenHouseTotalPriceIndex).PriceName);
		}
	}

	protected void refreshLocationButtonName() {
		if(mCurrenLocationIndex == 0){
			btn_locationSelete.setText("区域");
		}else{
			btn_locationSelete.setText(mSeleteRegionAdapter.data
					.get(mCurrenLocationIndex).ZoneName);
		}
	}
	
	/**
	 * 隐藏条件筛选
	 */
	private void hideSeleteArea() {
		ObjectAnimator animator = ObjectAnimator.ofFloat(lv_seleteArea_left,
				"translationY", 0, -lv_seleteArea_left.getHeight());
		animator.addListener(new Animator.AnimatorListener() {
			@Override
			public void onAnimationStart(Animator animation) {

			}

			@Override
			public void onAnimationEnd(Animator animation) {
				v_seleteArea.setVisibility(View.INVISIBLE);
			}

			@Override
			public void onAnimationCancel(Animator animation) {

			}

			@Override
			public void onAnimationRepeat(Animator animation) {

			}
		});

		ObjectAnimator translationRight = ObjectAnimator.ofFloat(lv_seleteArea_right, "translationY", 0,-lv_seleteArea_right.getHeight());
		ObjectAnimator alphaArea = ObjectAnimator.ofFloat(iv_seleteArea, "alpha", 1f, 0f);
		ObjectAnimator alphaRight = ObjectAnimator.ofFloat(lv_seleteArea_right, "alpha", 1f, 0f);
		AnimatorSet set = new AnimatorSet();
		set.playTogether(animator,translationRight,alphaArea,alphaRight);
		set.start();

	}
	
	 private void showSeleteArea() {

	        ViewTreeObserver vto2 = lv_seleteArea_left.getViewTreeObserver();

	        vto2.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
	            @Override
	            public void onGlobalLayout() {
	            	lv_seleteArea_left.getViewTreeObserver().removeGlobalOnLayoutListener(this);
	            	
//	                int height =  v_seleteArea.getHeight() / 2;
//	                DebugLog.e("height: " + height);
	                
	                if (lv_seleteArea_left.getAdapter() instanceof HouseSeleteMoreAdapter) {
//	                    ViewGroup.LayoutParams layoutParams = lv_seleteArea_right.getLayoutParams();
//	                    layoutParams.height = height;
//	                    lv_seleteArea_right.setLayoutParams(layoutParams);
	                    lv_seleteArea_right.setVisibility(View.VISIBLE);
	                } else {
	                	lv_seleteArea_right.setVisibility(View.GONE);
	                }
	                
	                ObjectAnimator animatorLeft = ObjectAnimator.ofFloat(lv_seleteArea_left, "translationY", -lv_seleteArea_left.getHeight(), 0);

	                animatorLeft.addListener(new Animator.AnimatorListener() {
	                    @Override
	                    public void onAnimationStart(Animator animation) {

	                        v_seleteArea.setVisibility(View.VISIBLE);

	                    }

	                    @Override
	                    public void onAnimationEnd(Animator animation) {

	                    }

	                    @Override
	                    public void onAnimationCancel(Animator animation) {

	                    }

	                    @Override
	                    public void onAnimationRepeat(Animator animation) {

	                    }
	                });
	                ObjectAnimator alphaArea = ObjectAnimator.ofFloat(iv_seleteArea, "alpha", 0f, 1f);
	                ObjectAnimator translationRight = ObjectAnimator.ofFloat(lv_seleteArea_right, "translationY", -lv_seleteArea_right.getHeight(), 0);
	                ObjectAnimator alphaRight = ObjectAnimator.ofFloat(lv_seleteArea_right, "alpha", 0f, 1f);
	                AnimatorSet set = new AnimatorSet();
	                set.playTogether(animatorLeft,translationRight,alphaArea,alphaRight);
	                set.start();
	            }
	        });
	    }
	 /**
	  * 搜索关键字
	  */
	private String searchKey = "";
	private void load(boolean isFrist) {
		isFirstLoad = isFrist;
		int page;
		//面积
		String proportionValue = "";
		//区域id
		int zoneId = 0;
		//总价范围
		String totalPrice = "";
		
		if (mCurrenProportionIndex > 0) {
			proportionValue = mSelectProportionAdapter.data.get(mCurrenProportionIndex).h_mjID;
		}
		if (mCurrenLocationIndex > 0) {
			zoneId = mSeleteRegionAdapter.data.get(mCurrenLocationIndex).ZoneID;
		}
		
		if (mCurrenHouseTotalPriceIndex > 0) {
			totalPrice = mSeletePriceAdapter.data.get(mCurrenHouseTotalPriceIndex).PriceID;
		}
		/*if (mCurrenMoreLeftIndex > 0) {
			HouseMoreSeleteCategoryBean houseMoreSeleteCategoryBean = mSelectMoreLeftAdapter.data.get(mCurrenMoreLeftIndex);
			HouseMoreCategoryItemValuesBean houseMoreCategoryItemValuesBean = houseMoreSeleteCategoryBean.values.get(mCurrenMoreRightIndex);
			orderType = houseMoreCategoryItemValuesBean.urlValue; // urlValue = "orderSUP=asc"
		}*/
		
		String moreUrl = "";
		if(mSelectMoreLeftAdapter.data != null){
			for (HouseMoreSeleteCategoryBean more : mSelectMoreLeftAdapter.data) {
				if (more.childSelete >= 0) {
					// orderTime=asc&
					if(more.urlKey.equals("order")){ // 排序只拿 urlValue 
						moreUrl = moreUrl + more.values.get(more.childSelete).urlValue + "&";
					}else{
						moreUrl = moreUrl + more.urlKey + "="
								+ more.values.get(more.childSelete).urlValue + "&";
					}
				}
			}
		}
		
		//是否是第一次加载 | 或者更改筛选条件后重新加载
		if (isFirstLoad) {
			page = 1;
		} else {
			//追加数据
			page = mHouseListAdapter.getCount() / limit  + 1;
		}
		addRequestHandle(ApiRequest.getOldHouseListData(this,searchKey,zoneId, totalPrice, proportionValue, moreUrl, page, limit,
				new HttpOldHouseListHandler(this,false)));
		
		DebugLog.i("zoneId:" + zoneId);
		DebugLog.i("orderType:" + proportionValue);
		DebugLog.i("PriceID:" + totalPrice);
		DebugLog.i("moreUrl:" + moreUrl);
		DebugLog.i("searchKey:" + searchKey);
		DebugLog.i("page:" + page);
		 
	}

	private void loadMore() {
		load(false);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_oldhouse_list_locationSelete:
			if (v_seleteArea.getVisibility() == View.VISIBLE) {
				if (lv_seleteArea_left.getAdapter() instanceof NewHouseSelectRegionAdapter) {
					hideSeleteArea();
				} else {                 
					lv_seleteArea_left.setAdapter(mSeleteRegionAdapter);
					mSeleteRegionAdapter.notifyDataSetChanged();
					lv_seleteArea_right.setVisibility(View.GONE);
				}
			} else {
				lv_seleteArea_left.setAdapter(mSeleteRegionAdapter);
				mSeleteRegionAdapter.notifyDataSetChanged();
				lv_seleteArea_right.setVisibility(View.GONE);
				showSeleteArea();
			}

			break;
		case R.id.btn_oldhouse_list_priceSelete:
			if (v_seleteArea.getVisibility() == View.VISIBLE) {
				if (lv_seleteArea_left.getAdapter() instanceof NewHouseSelectPriceAdapter) {
					hideSeleteArea();
				} else {
					lv_seleteArea_left.setAdapter(mSeletePriceAdapter);
					mSeletePriceAdapter.notifyDataSetChanged();
					lv_seleteArea_right.setVisibility(View.GONE);
				}
			} else {
				lv_seleteArea_left.setAdapter(mSeletePriceAdapter);
				mSeletePriceAdapter.notifyDataSetChanged();

				showSeleteArea();
			}

			break;

		case R.id.btn_oldhouse_list_proportionSelete:
			if (v_seleteArea.getVisibility() == View.VISIBLE) {
				if (lv_seleteArea_left.getAdapter() instanceof HouseSelectProportionAdapter) {
					hideSeleteArea();
				} else {
					lv_seleteArea_left.setAdapter(mSelectProportionAdapter);
					mSelectProportionAdapter.notifyDataSetChanged();
					lv_seleteArea_right.setVisibility(View.GONE);
				}
			} else {
				lv_seleteArea_left.setAdapter(mSelectProportionAdapter);
				mSelectProportionAdapter.notifyDataSetChanged();
				
				showSeleteArea();
			}
			break;
		case R.id.btn_oldhouse_list_moreSelete:
			if (v_seleteArea.getVisibility() == View.VISIBLE) {
				if (lv_seleteArea_left.getAdapter() instanceof HouseSeleteMoreAdapter) {
					hideSeleteArea();
				} else {
					lv_seleteArea_left.setAdapter(mSelectMoreLeftAdapter);
					mSelectMoreLeftAdapter.notifyDataSetChanged();

					lv_seleteArea_right.setVisibility(View.VISIBLE);
					lv_seleteArea_right.setAdapter(mSeleteMoreRightAdapter);
					mSeleteMoreRightAdapter.data = mSelectMoreLeftAdapter.data.get(mCurrenMoreLeftIndex);
					mSeleteMoreRightAdapter.notifyDataSetChanged();
				}
			} else {
				lv_seleteArea_left.setAdapter(mSelectMoreLeftAdapter);
				mSelectMoreLeftAdapter.notifyDataSetChanged();
				lv_seleteArea_right.setVisibility(View.VISIBLE);
				lv_seleteArea_right.setAdapter(mSeleteMoreRightAdapter);
				mSeleteMoreRightAdapter.data = mSelectMoreLeftAdapter.data.get(mCurrenMoreLeftIndex);
				mSeleteMoreRightAdapter.notifyDataSetChanged();


				showSeleteArea();
			}
			break;
		}
	}

	class HttpOldHouseListHandler extends JsonHttpHandler {

		public HttpOldHouseListHandler(Context context, boolean fromCache) {
			super(context, fromCache);
			// TODO Auto-generated constructor stub
		}

		public HttpOldHouseListHandler(Context context) {
			super(context);
			// TODO Auto-generated constructor stub
		}

		@Override
		public void onStart() {
			if (isFirstLoad) {
//				mLoading.setVisibility(View.VISIBLE);
				setShowProgressDialog("正在加载中...");
//				plv_houseList.setRefreshing(true);
			} else {
				//增加加载更多
				plv_houseList.setRefreshing(true);
			}
			super.onStart();
		}

		@Override
		public void onFinish() {
			super.onFinish();
			plv_houseList.onRefreshComplete();
		}

		@Override
		public void onDo(String response) {
			plv_houseList.onRefreshComplete();
			super.onDo(response);
			try {
				List<OldHouseBean> entities = new Gson().fromJson(response,
						new TypeToken<List<OldHouseBean>>() {}.getType());
				if (isFirstLoad) {
					mHouseListAdapter.houseList.clear();
				}
				//获取回来的数据小于每页的数据  则说明没有更多数据了
				if (entities == null ||entities.size() < limit) {
					plv_houseList.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
					isNoMore = true;
				}else{
					plv_houseList.setMode(PullToRefreshBase.Mode.BOTH);
					DebugLog.i("entities.size():" + entities.size());
					mHouseListAdapter.houseList.addAll(entities);
				}
				mHouseListAdapter.notifyDataSetChanged();
				
				if(isFirstLoad){
					plv_houseList.getRefreshableView().setSelection(0);
				}
				
				DebugLog.i("mAdapter.getCount():" + mHouseListAdapter.getCount());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if(requestCode == SEARCH_REQUEST_CODE && resultCode == RESULT_OK && data != null){
			String stringExtra = data.getStringExtra("search_key");
			searchKey = stringExtra;
			
			if(!TextUtils.isEmpty(searchKey)){
				showTitle("搜索 \"" + searchKey + "\"");
			}else{
				showTitle("买二手房");
			}
			
			fistLoad();
			return;
		}
	}
	
	@Override
	public void onBackPressed() {
		if(v_seleteArea.getVisibility() == View.VISIBLE){
			hideSeleteArea();
			return;
		}
		super.onBackPressed();
	}
	
	
}
